VERSION 5.00
Begin VB.Form frmLibroIva 
   BackColor       =   &H80000013&
   Caption         =   "Imprimir Libro Iva"
   ClientHeight    =   4200
   ClientLeft      =   60
   ClientTop       =   450
   ClientWidth     =   7875
   LinkTopic       =   "Form2"
   MDIChild        =   -1  'True
   ScaleHeight     =   4200
   ScaleWidth      =   7875
   Begin VB.Frame fraperiodo 
      BackColor       =   &H80000013&
      Caption         =   "Seleccionar Datos"
      Height          =   2415
      Left            =   120
      TabIndex        =   4
      Top             =   120
      Width           =   7455
      Begin VB.CheckBox chkContado 
         BackColor       =   &H80000013&
         Caption         =   "Incluir Facturas de Contado"
         Height          =   255
         Left            =   2040
         TabIndex        =   8
         Top             =   1080
         Width           =   2535
      End
      Begin VB.CheckBox chkSaldo 
         BackColor       =   &H80000013&
         Caption         =   "con Saldo"
         Height          =   255
         Left            =   120
         TabIndex        =   7
         Top             =   1080
         Width           =   1335
      End
      Begin VB.CommandButton cmdVer 
         Caption         =   "&Ver"
         Height          =   855
         Left            =   5640
         Style           =   1  'Graphical
         TabIndex        =   2
         Top             =   360
         Width           =   1335
      End
      Begin VB.PictureBox dtpHasta 
         Height          =   375
         Left            =   3720
         ScaleHeight     =   315
         ScaleWidth      =   1395
         TabIndex        =   1
         Top             =   360
         Width           =   1455
      End
      Begin VB.PictureBox dtpDesde 
         BeginProperty DataFormat 
            Type            =   1
            Format          =   "dd/MM/yyyy"
            HaveTrueFalseNull=   0
            FirstDayOfWeek  =   0
            FirstWeekOfYear =   0
            LCID            =   11274
            SubFormatType   =   3
         EndProperty
         Height          =   375
         Left            =   1200
         ScaleHeight     =   315
         ScaleWidth      =   1275
         TabIndex        =   0
         Top             =   360
         Width           =   1335
      End
      Begin VB.Label lblhasta 
         BackColor       =   &H80000013&
         Caption         =   "Hasta:"
         BeginProperty Font 
            Name            =   "MS Sans Serif"
            Size            =   12
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   375
         Left            =   2880
         TabIndex        =   6
         Top             =   360
         Width           =   735
      End
      Begin VB.Label lbldesde 
         BackColor       =   &H80000013&
         Caption         =   "Desde:"
         BeginProperty Font 
            Name            =   "MS Sans Serif"
            Size            =   12
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   255
         Left            =   240
         TabIndex        =   5
         Top             =   360
         Width           =   855
      End
   End
   Begin VB.CommandButton cmdSalir 
      Caption         =   "Ce&rrar"
      Height          =   855
      Left            =   5880
      Style           =   1  'Graphical
      TabIndex        =   3
      Top             =   3000
      Width           =   1455
   End
End
Attribute VB_Name = "frmLibroIva"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim cliente As String
Dim imprime As Integer

Private Sub chkTodos_Click()
If chkTodos.Value = 1 Then
    txtCliente1.deshabilitar
Else
    txtCliente1.habilitar (True)
End If

End Sub


Private Sub cmdVer_Click()

If txtCliente1.Text = "" And chkTodos.Value = 0 Then
    MsgBox "Ingrese el cliente", vbExclamation, "Atencion"
Else

If dtpHasta.Value < dtpDesde.Value Then
    MsgBox "La fecha inicial debe ser anterior o igual a la final", vbExclamation, "Atencion"
Else

    If chkTodos.Value = 1 Then
        If chkSaldo = 1 Then
            sSaldo = " and dbo.f_saldo(id_cliente) <> 0 "
        Else
            sSaldo = ""
        End If
    End If
    If chkTodos.Value = 0 Then
        cliente = " and id_cliente = " & txtCliente1.Text
        
    Else
        cliente = ""
    End If
    
    rptResumen.Sections.Item("cmdResumen_Header").Controls("rptNombre").Caption = parametro(1)
    rptResumen.Sections.Item("cmdResumen_Header").Controls("rptDe").Caption = "De: " & parametro(2)
    rptResumen.Sections.Item("cmdResumen_Header").Controls("lbldel").Caption = dtpDesde.Value
    rptResumen.Sections.Item("cmdResumen_Header").Controls("lblal").Caption = dtpHasta.Value
    rptResumen.Sections.Item("cmdResumen_Footer").Controls("lblLeyenda").Caption = parametro(3)
    
    cn.Execute "if exists (select * from dbo.sysobjects where name = 'trans')" & _
               "drop table [dbo].[trans]"
    cons = "Select IDENTITY(int, 1,1) numero, id_cliente, tipo , fecha, debe, haber, comprobante, concepto, contado "
    cons = cons & "INTO trans from v_transaccion WHERE 1 = 1"
    cons = cons & cliente
    cons = cons & saldo
    If chkContado.Value = 0 Then
        cons = cons & " and contado = 0  "
    End If
    cons = cons & "ORDER BY fecha asc, tipo asc "
    cn.Execute cons
    
    cons = " SHAPE {select  id_cliente, nombreorazonsocial, nombre,"
    cons = cons & " dbo.f_saldo( id_cliente) as saldo, domicilio, cuit, telefono, "
    cons = cons & " dbo.f_saldoanterior( id_cliente, ' " & dtpDesde.Value & " ' ) as saldoanterior "
    cons = cons & "from cliente c, ciudad ciu "
    cons = cons & " Where ciu.id_ciudad = c.id_ciudad "
    cons = cons & cliente
    cons = cons & sSaldo
    cons = cons & " order by nombreorazonsocial } "
    cons = cons & " AS cmdResumen "
    cons = cons & " APPEND ({ select id_cliente,  "
    cons = cons & " tipo , fecha, debe, haber, comprobante, concepto, contado, "
    cons = cons & "(SELECT isnull(sum(isnull(debe,0))-sum(isnull(haber,0)),0) "
    cons = cons & "FROM trans t2 WHERE t2.numero <= t1.numero "
    cons = cons & "and t1.id_cliente = t2.id_cliente) as saldoacumulado "
    cons = cons & " from Trans t1 "
    cons = cons & " where fecha  >= ' " & dtpDesde.Value & " ' and fecha  <= ' " & dtpHasta.Value & " ' "
    cons = cons & " } AS cmdResumenDetalle "
    cons = cons & " RELATE 'id_cliente' TO 'id_cliente') AS cmdResumenDetalle "
    Dte.Commands("cmdResumen").CommandText = cons
    Dte.Commands("cmdResumen").Execute

    'rptResumen.Orientation = rptOrientPortrait
    
    rptResumen.Show vbModal
    
End If
End If
End Sub







Private Sub cmdSalir_Click()
Unload Me
End Sub

Private Sub dtpHasta_Click()

End Sub

Private Sub Form_Load()

dtpDesde.Value = Date - 30
dtpHasta.Value = Date
chkSaldo = 1

End Sub


